package com.elinshaw.singleton;

/**
 * 枚举单例
 *
 * @author Administrator
 */
public final class SingletonEnum {

    private SingletonEnum() {
    }

    public static SingletonEnum getInstance() {
        return Singleton.INSTANCE.getInstance();
    }

    /**
     * 使用枚举方法实现单利模式
     */
    private enum Singleton {
        INSTANCE;

        private SingletonEnum instance;

        /**
         * JVM保证这个方法绝对只调用一次
         */
        Singleton() {
            instance = new SingletonEnum();
        }

        public SingletonEnum getInstance() {
            return instance;
        }
    }


}
